package com.more.offer.threadtest.threadlocal;

import java.util.LinkedHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * @author pinoc
 * @date 2021/6/20
 * @description
 */
public class InheritableThreadLocalTest {

	public static ThreadLocal<String> local = new ThreadLocal<>();
	/**
	 * 子线程可以访问父线程的threadLocal 变量值
	 */
	public static ThreadLocal<String> local1 = new InheritableThreadLocal<>();

	public static void main(String[] args) {
		local.set("main value");
		local1.set("main value2");

		Thread thread = new Thread(new Runnable() {
			@Override
			public void run() {
				System.out.println(Thread.currentThread().getName());
				System.out.println("sub threadlocal value: " + local.get());
				System.out.println("sub InheritableThreadLocal value: " + local1.get());
			}
		});

		thread.start();

		System.out.println("main threadLocal value: " + local.get());
		System.out.println("main InheritableThreadLocal value: " + local1.get());

		local.remove();
		local1.remove();
	}

}
